{extend name="public:base"}
{block name="main"}
<form class="layui-form">
  <div class="demoTable">
    条件搜索：
    <div class="layui-inline">
      <select name="cateid">
        <option value="">全部分类</option>
        {notempty name="catelist"}
          {foreach $catelist as $v}
          <option value="{$v['cateid']}">{$v['catename']}</option>
          {/foreach}
        {/notempty}
      </select> 
    </div>
    <div class="layui-inline">
      <select name="authorid">
        <option value="">全部作者</option>
        {notempty name="authorlist"}
          {foreach $authorlist as $v}
          <option value="{$v['authorid']}">{$v['name']}</option>
          {/foreach}
        {/notempty}
      </select> 
    </div>
    <div class="layui-inline">
      <select name="wheretype">
        <option value="">全部状态</option>
        <option value="ishot">已推荐</option>
        <option value="nohot">未推荐</option>
        <option value="istop">已置顶</option>
        <option value="notop">未置顶</option>
        <option value="isstatus">正常</option>
        <option value="nostatus">下架</option>
        <option value="caogao">草稿</option>
      </select> 
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入关键字">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="start" id="start"  placeholder="请输入发布开始时间">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="end" id="end"  placeholder="请输入发布结束时间">
    </div>
    <div class="layui-inline">
      <button class="layui-btn" lay-filter="search" lay-submit>搜索</button>
      <button class="layui-btn layui-btn-primary"  lay-filter="search" lay-submit>重置</button>
      <a href="javascript:LayerOpen('{:url('news/newsadd')}');" class="layui-btn layui-btn-normal" >添加新闻</a>
    </div>

  </div>
</form>
<table class="layui-table" lay-data="{height:650,url:location.href,where:{cateid:'{:input('cateid')}'}, page:true, id:'table',toolbar:'#tool'}" lay-filter="table" lay-size="lg">
  <thead>
    <tr>
      <th lay-data="{type: 'checkbox', fixed: 'left'}"></th>
      <th lay-data="{field:'newsid',width:75}">ID</th>
      <th lay-data="{field:'thumb',templet:'#thumb',width:75}">缩略图</th>
      <th lay-data="{field:'catename',width:100}">所属分类</th>
      <th lay-data="{field:'title',templet:'#link'}">标题</th>
      <th lay-data="{field:'hits',width:100}">读/赞/评</th>
      <th lay-data="{field:'authorname',width:100}">作者</th>
      <th lay-data="{field:'status',templet:'#status',width:150}">状态</th>
      <th lay-data="{field:'pushtime',width:180}">发布时间</th>
      <th lay-data="{field:'uptime',width:180}">修改时间</th>
      <!-- <th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barDemo'}">操作</th> -->
    </tr>
  </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>

<script type="text/html" id="tool">
  <a class="layui-btn layui-btn-xs" lay-event="on_upper">上架</a>
  <a class="layui-btn layui-btn-xs" lay-event="on_down">下架</a>
  <a class="layui-btn layui-btn-xs" lay-event="on_top">置顶</a>
  <a class="layui-btn layui-btn-xs" lay-event="no_top">取消置顶</a>
  <a class="layui-btn layui-btn-xs" lay-event="on_hot">推荐</a>
  <a class="layui-btn layui-btn-xs" lay-event="no_hot">取消推荐</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="on_del">删除</a>
  <!-- <a class="layui-btn layui-btn-xs" lay-event="LookPdf">查看pdf</a>
  <a class="layui-btn layui-btn-xs" lay-event="DownPdf">导出pdf</a> -->
  <!-- <a class="layui-btn layui-btn-xs" lay-event="LookWord">查看word</a>
  <a class="layui-btn layui-btn-xs" lay-event="DownWord">导出word</a> -->
</script>

<script>
layui.use(['table','laydate','form'], function(){
  
  table = layui.table;
  laydate = layui.laydate;
  form = layui.form;

  table.on('toolbar(table)', function(obj){

      //var newsid = table.checkStatus(obj.config.id).data[0].newsid;

      switch(obj.event){
        case 'LookPdf':
          LayerOpen("articlepdf/newsid/"+table.checkStatus(obj.config.id).data[0].newsid);
        break;
        case 'DownPdf':
          window.location.href = "articlepdf/newsid/"+table.checkStatus(obj.config.id).data[0].newsid+"/type/D";
        break;
        case 'LookWord':
          LayerOpen("articleword/newsid/"+newsid);
        break;
        case 'DownWord':
          window.location.href = "articleword/newsid/"+newsid+"/type/D";
        break;
        case 'edit':
          LayerOpen("newsedit/newsid/"+table.checkStatus(obj.config.id).data[0].newsid);
        break;
        case 'on_del':

          var arr = [];

          var data = table.checkStatus(obj.config.id).data;

          if(data.length == 0){
            alert('最起码选择一行');

          }else{

              $.each(data, function(i, k){     
                 arr.push(k.newsid); 
              }); 

              Delete("{:Url('newsdel')}",{'newsid': arr });
            
          }

        break;

        case 'LAYTABLE_COLS':
        
        break;

        default:

          var arr = [];

          var data = table.checkStatus(obj.config.id).data;

          if(data.length == 0){

            alert('最起码选择一行');

          }else{

              $.each(data, function(i, k){     
                 arr.push(k.newsid); 
              }); 

              Status("{:url('NewsStatusUp')}",{set:obj.event,'newsid':arr});
            
          }

      };
      
  });

  admin.init(['search','laydate']);
 

  table.on('tool(table)', function(obj){
    var data = obj.data;

    if(obj.event === 'del'){

      Delete("{:Url('newsdel')}",{'newsid': data.newsid});
      
    } else if(obj.event === 'edit'){

        LayerOpen("newsedit/newsid/"+data.newsid);

    } 

  });

  admin.switch({ url : 'newsup'});
 
});

</script>


<script type="text/html" id="link">
  {{#  if(d.url != '' && typeof(d.url) != 'undefined'){ }}
     <a href="{{d.url}}" class="layui-table-link" target="_blank">{{d.title}}</a>
  {{#  } else { }}
    {{d.title}}
  {{#  } }}
</script>
<script type="text/html" id="thumb">
  <img src='{{d.thumb}}'>
</script>

<script type="text/html" id="status">
  {{#  if(d.status == '1'){ }}
    <span class="layui-badge layui-bg-green">上架</span>
  {{#  } }}
  {{#  if(d.status == '0'){ }}
    <span class="layui-badge layui-bg-gray">下架</span>
  {{#  } }}
  {{#  if(d.status == '-1'){ }}
    <span class="layui-badge layui-bg-blue">草稿</span>
  {{#  } }}
  {{#  if(d.hot == '1'){ }}
    <span class="layui-badge layui-bg-orange">推荐</span>
  {{#  } }}
  {{#  if(d.top == '1'){ }}
    <span class="layui-badge ">置顶</span>
  {{#  } }}
</script>

<script type="text/html" id="count">
    <span class="layui-badge layui-bg-gray" title="图片 {{d.count.img}}个"><i class="layui-icon">&#xe60d;</i> {{d.count.img}}</span>
    <span class="layui-badge layui-bg-gray " title="附件 {{d.count.file}}个"><i class="layui-icon">&#xe621;</i> {{d.count.file}} </span>
    <span class="layui-badge layui-bg-gray " title="评论 {{d.count.comment}}个"><i class="layui-icon">&#xe611;</i> {{d.count.comment}} </span>
</script>




{/block}